package com.woniuxy02;

/**
 * @author 作者
 * @create 2025-06-23 15:37
 */
public class TicketThread extends Thread {

    static int num = 100;

    @Override
    public void run() {
        synchronized (TicketThread.class) {
            try {
                //线程休眠，运行到这里会停止100毫秒.模拟网络拥堵，高并发
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            //synchronized (锁对象)，必须是同一把锁，一个锁对象
            while (true) {
                if (num > 0) {
                    System.out.println(getName() + "窗口售出,还剩" + (--num));
                }
            }
        }
    }
}
